Home:ALL Converter>Onclick show next divs

Onclick show next divs

Ask Time:2012-06-22T04:34:27         Author:zahid

Json Formatter

I have 1000 divs and 20 of them are visible and remaining are hidden.

In the onClick jquery event, I want the next 20 divs to become visible and so on.

Author:zahid,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/11146298/onclick-show-next-divs
swatkins :

If you're using jquery, you can use the .slice() method. \n\nhttp://api.jquery.com/slice/\n\nSomething like:\n\n$('button').click(function(e){\n var divs = $('.mydivs');\n divs.hide().slice(0, 20).show(); // 0 is the starting index\n});\n\n\nYou'd just need to figure out the logic to determine what your starting index is.\n\nI don't have a non-jquery solution, maybe someone else could help on that front.",
2012-06-21T20:43:48
GrayFox374 :

Assign sets of 20 to css classes, and have your jQuery method show all in that class. You can have a global js variable track number of clicks, then if an if statement, show hide the appropriate sections:\n\n<script type=\"text/javascript\">var numberOfClicks = 0;</script>\n<style>.IncurredDate1 {} .IncurredDate2 ... {}</style>\n<div class=\"incurredRow1\">blah</div>\n<div class=\"incurredRow2\">blah</div>\n//in click event\n<script type=\"text/javascript\">\nfunction buttonClick(event){\n switch(numberOfClicks )\n {\n case 1:\n ...\n case 20; \n $(\".incurredRow1\").show();\n break;\n case 21:\n ...\n case 40:\n $(\".incurredRow2\").show();\n break;\n default:\n code to be executed if n is different from case 1 and 2\n }\n }(); \n</script>\n",
2012-06-21T20:41:07
yy